demos.ROSpanel2 = Ext.extend( Ext.Toolbar, {
    centered: false,
    btnCount: 0,
    bitWise: 0,
	dock: 'top',
	panelItems: [],
//   html: 'Test1',
//   id: ROSpanel,
    initComponent: function() {
//    	demos.ROSpanel2.panelItems = new Array();
    	
    	Ext.apply(this, {
	        scroll: {
	            direction: 'horizontal',
	            useIndicators: false
	        },
	        defaults: {
	            xtype: 'button',
	            width: 120,
	            scope: this,
	            handler:  this.buttonPN,
	        },
	        panelItems: this
        });
        
    	this.addEvents('rosbutton');    	
        this.enableBubble('rosbutton');
        
    	demos.ROSpanel2.superclass.initComponent.apply(this, arguments);
    },
    
    
//	getBubbleTarget: function() {
//	    return examcontrol;
//	},
	
    buttonPN: function (btn, evt) {
        //Setting up the button ui...    	
    	var panels = this;
    	
        var bitwise = 0;
        var temp = panels.btnCount;
        var ROSitems = panels.items;
        var ROSbadge = ROSitems.items[0];
        var ROSbNumber = parseInt(panels.btnCount);
            ROSnNumber = isNaN(ROSbNumber) ? 0 : ROSbNumber;
            
        var chgBadge = function(x, idx) {
            if (idx>1) {
                bitwise += temp%2;
                temp = Math.floor(temp/2);
            }
//                    console.debug(ROSpanel.btnCount+':'+temp+':'+bitwise);
        };

        var isThisAdd = function(x, idx) {
            // returns true if x is current item
            if (btn.id == ROSitems.items[idx].id) {
                ROSnNumber += Math.pow(2,idx-2);
                panels.btnCount = ROSnNumber;
//                        console.debug(ROSpanel.btnCount+':'+temp+':'+bitwise);
//                        ToolbarDemo.views.Patientdetail.update;
            }
        };

        var isThisSub = function(x, idx) {
            // returns true if x is current item
            if (btn.id == ROSitems.items[idx].id) {
                ROSnNumber -= Math.pow(2,idx-2);
                temp -= Math.pow(2,idx-2);
                panels.btnCount = ROSnNumber;
//                        console.debug(ROSpanel.btnCount+':'+temp+':'+bitwise);
                ROSitems.items[0].update;
//                        ToolbarDemo.views.Patientdetail.update;
            }
        };

        if(btn.ui == 'normal'){
            btn.ui = 'confirm';
            btn.el.removeCls('x-button-normal');
            btn.el.addCls('x-button-confirm');
            ROSitems.items.forEach(isThisAdd);
            temp = panels.btnCount;
            ROSitems.items.forEach(chgBadge);
            ROSbadge.setBadge(bitwise);
//                    Ext.getCmp('const1').setBadge(bitwise);
//                    Ext.getCmp('const2').setBadge(bitwise);
//                    console.debug(bitwise);
//                    console.debug(this.id);
//                    ROSbadge.Button.setBadge(this.getId());
//                    console.log(ToolbarDemo.ROSpanel.items.items.indexOf(this.id));  //.tab.badgeText = '1';
        } else {
            if (btn.ui == 'confirm'){
            btn.ui = 'decline';                                
            btn.el.removeCls('x-button-confirm');
            btn.el.addCls('x-button-decline');
            bitwise = panels.bitWise;
            } else {
                btn.ui = 'normal';
                btn.el.removeCls('x-button-decline');
                btn.el.addCls('x-button-normal');
                ROSitems.items.forEach(isThisSub);
                temp = panels.btnCount;
                ROSitems.items.forEach(chgBadge);
      // KR          console.debug(bitwise);
                ROSbadge.setBadge(bitwise);
      //          Ext.getCmp('const1').setBadge(bitwise);
      //          Ext.getCmp('const2').setBadge(bitwise);
            }
        };
        
        panels.bitWise = bitwise;
        
    	this.fireEvent('rosbutton');
    }
});

Ext.reg('rospanel', demos.ROSpanel2);
